<?php 
if(!isset($_SESSION)) 
{ 
	session_start(); 
}
if(isset($_REQUEST['ten']) && isset($_REQUEST['winW'])){
	$w=$_REQUEST['winW']*90/100;
	$mm=$w."px";
	$c1=$w*10/100;
	$c2=$w*20/100;
	$c4=200;
	$c3=$w-($c1+$c2+$c4);
	include '../sort/sorclass.php';
	$ten=$_REQUEST['ten'];
	if('datetime'==$ten){
		$_SESSION['msort'][$ten]=!$_SESSION['msort'][$ten];
		$sl=count($_SESSION['mrs']);
		if($sl>0){
			?>
			<table cellspacing="0" cellpadding="0" border="1" width="<?php echo $mm;?>" >
				<tr><td colspan="4"><?=$sl?></td></tr>
				<?php 
				if($_SESSION['msort'][$ten]==1){
					for($i=0;$i<$sl;$i++){
						$obj=unserialize (serialize($_SESSION['mrs'][$i]));
						?>
						<tr>
			             <td width="<?php echo $c1."px";?>"><?=$obj->id?></td>
			             <td width="<?php echo $c2."px";?>"><?=$obj->name?></td>
			             <td width="<?php echo $c3."px";?>"><?=$obj->carnum?></td>
			             <td width="<?php echo $c4."px";?>"><?=$obj->datetime?></td>
			           	</tr>
						<?php 
					}
				}else{
					for($i=($sl-1);$i>=0;$i--){
						$obj=unserialize (serialize($_SESSION['mrs'][$i]));
						?>
						<tr>
			             <td width="<?php echo $c1."px";?>"><?=$obj->id?></td>
			             <td width="<?php echo $c2."px";?>"><?=$obj->name?></td>
			             <td width="<?php echo $c3."px";?>"><?=$obj->carnum?></td>
			             <td width="<?php echo $c4."px";?>"><?=$obj->datetime?></td>
			           	</tr>
						<?php
					}
				}
				?>
			</table>
			<?php 
		}
	}else if('name'==$ten){
		if(isset($_SESSION['mname'])){
			$_SESSION['msort'][$ten]=!$_SESSION['msort'][$ten];
		}else{
			$_SESSION['mname']=array();
			$tem=$_SESSION['mrs'];
			$_SESSION['temname']=array_keys($_SESSION['temname']);
			sort($_SESSION['temname']);
			$soluong=count($_SESSION['temname']);
			if($soluong>0){
				for($i=0;$i<$soluong;$i++){
					foreach($tem as $k=>$vl){
						$oj=unserialize (serialize($tem[$k]));
						if($oj->name==$_SESSION['temname'][$i]){
							$_SESSION['mname'][]=$oj;
							unset( $tem[$k] );
						}
					}
				}
			}
		}
		$sl=count($_SESSION['mname']);
		if($sl>0){
			?>
			<table cellspacing="0" cellpadding="0" border="1" width="<?php echo $mm;?>" >
				<tr><td colspan="4"><?=$sl?></td></tr>
				<?php 
				if($_SESSION['msort'][$ten]==1){
					for($i=0;$i<$sl;$i++){
						$obj=unserialize (serialize($_SESSION['mname'][$i]));
						?>
						<tr>
			             <td width="<?php echo $c1."px";?>"><?=$obj->id?></td>
			             <td width="<?php echo $c2."px";?>"><?=$obj->name?></td>
			             <td width="<?php echo $c3."px";?>"><?=$obj->carnum?></td>
			             <td width="<?php echo $c4."px";?>"><?=$obj->datetime?></td>
			           	</tr>
						<?php
					}
				}else{
					for($i=($sl-1);$i>=0;$i--){
						$obj=unserialize (serialize($_SESSION['mname'][$i]));
						?>
						<tr>
			             <td width="<?php echo $c1."px";?>"><?=$obj->id?></td>
			             <td width="<?php echo $c2."px";?>"><?=$obj->name?></td>
			             <td width="<?php echo $c3."px";?>"><?=$obj->carnum?></td>
			             <td width="<?php echo $c4."px";?>"><?=$obj->datetime?></td>
			           	</tr>
						<?php
					}
				}
				?>
			</table>
			<?php 
		}
	}else if('carnumber'==$ten){
		if(isset($_SESSION['mcarnum'])){
			$_SESSION['msort'][$ten]=!$_SESSION['msort'][$ten];
		}else{
			$_SESSION['mcarnum']=array();
			$tem=$_SESSION['mrs'];
			$_SESSION['temcarnum']=array_keys($_SESSION['temcarnum']);
			sort($_SESSION['temcarnum']);
			$soluong=count($_SESSION['temcarnum']);
			if($soluong>0){
				for($i=0;$i<$soluong;$i++){
					foreach($tem as $k=>$vl){
						$oj=unserialize (serialize($tem[$k]));
						if($oj->carnum==$_SESSION['temcarnum'][$i]){
							$_SESSION['mcarnum'][]=$oj;
							unset( $tem[$k] );
						}
					}
				}
			}
		}
		$sl=count($_SESSION['mcarnum']);
		if($sl>0){
			?>
			<table cellspacing="0" cellpadding="0" border="1" width="<?php echo $mm;?>" >
				<tr><td colspan="4"><?=$sl?></td></tr>
				<?php 
				if($_SESSION['msort'][$ten]==1){
					for($i=0;$i<$sl;$i++){
						$obj=unserialize (serialize($_SESSION['mcarnum'][$i]));
						?>
						<tr>
			             <td width="<?php echo $c1."px";?>"><?=$obj->id?></td>
			             <td width="<?php echo $c2."px";?>"><?=$obj->name?></td>
			             <td width="<?php echo $c3."px";?>"><?=$obj->carnum?></td>
			             <td width="<?php echo $c4."px";?>"><?=$obj->datetime?></td>
			           	</tr>
						<?php	
					}
				}else{
					for($i=($sl-1);$i>=0;$i--){
						$obj=unserialize (serialize($_SESSION['mcarnum'][$i]));
						?>
						<tr>
			             <td width="<?php echo $c1."px";?>"><?=$obj->id?></td>
			             <td width="<?php echo $c2."px";?>"><?=$obj->name?></td>
			             <td width="<?php echo $c3."px";?>"><?=$obj->carnum?></td>
			             <td width="<?php echo $c4."px";?>"><?=$obj->datetime?></td>
			           	</tr>
						<?php		
					}
				}
				?>
			</table>
			<?php 	
		}
	}
}
?>